package com.seeingtv.service.impl;

import com.seeingtv.common.utils.StringUtils;
import com.seeingtv.mapper.RoleMapper;
import com.seeingtv.model.Role;
import com.seeingtv.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author hubert
 * @date 2018/8/7
 * @description RoleServiceImpl
 */
@Service
public class RoleServiceImpl implements RoleService{

	@Autowired
	private RoleMapper roleMapper;

	/**
	 * 根据用户ID查询角色
	 *
	 * @param userId 用户ID
	 * @return 角色列表
	 */
	@Override
	public Set<String> selectRoleKeys(Long userId) {
		List<Role> perms = roleMapper.selectRolesByUserId(userId);
		Set<String> permsSet = new HashSet<>();
		for (Role perm : perms) {
			if (StringUtils.isNotNull(perms)) {
				permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
			}
		}
		return permsSet;
	}
}
